/*
 * @file add_user_bottom
 * @Author: liuer
 * @Date: 2024/8/28 17:24
 * @LastModified: 2024-08-28 17:24
 * @LastModifiedBy: liuer
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/site_setting/site_setting_base_info/widgets/remark_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

class AddUserBottom extends StatefulWidget {
  final List pushTypeList; //告警推送方式
  final List pushLevelList ;//推送级别数组
  final TextEditingController remarkController;
  final Function(List) pushTypeCallBack;
  final Function(List)   pushLeveCallBack;
  final Function(String?) callBack;
  final bool isCanEdit;
  const AddUserBottom( this.pushTypeList, this.pushLevelList,this.remarkController,
      this.pushTypeCallBack,this.pushLeveCallBack,this.callBack,{this.isCanEdit = true,super.key});


  @override
  State<AddUserBottom> createState() => _AddUserBottomState();
}

class _AddUserBottomState extends State<AddUserBottom> {
  // List pushTypeList = [];//推送方法数组
  // List pushLevelList = [];//推送级别数组
  List pushTypeStringList = [ResKey.appMessagePush.tr,ResKey.mineUserManagerUserEmail.tr];
  List stringList = ['error','alarm',  'warn', 'info'];
  List pushLeveStringList = [ResKey.error.tr,ResKey.alarmImportant.tr,ResKey.warn.tr,ResKey.info.tr];//推送级别数组
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override

  Widget build(BuildContext context) {
    Log.d('pushTypeList===1111' +widget. pushLevelList.toString());
    return Container(
      clipBehavior: Clip.hardEdge,
      margin:  const EdgeInsets.only(left: 16,right: 16),
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.only(bottomLeft: Radius.circular(8),bottomRight: Radius.circular(8),),
        color: Colors.white,
      ),
      child: Column(
        children: [
          Container(
            height: 50,
            // color: Colors.red,
            child: Row(
              children: [
                Container(
                  alignment: Alignment.center,
                  margin: const EdgeInsets.only(left: 6, right: 2),
                  child: Text(
                    '*',
                    style: ytTextStyle(
                        color: Colour.warningTextColor,
                        fontWeight: FontWeight.w500),
                  ),
                ),
                Text(
                    ResKey.alarmPushType.tr,
                  style: ytTextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.normal,
                      color: Colour.mainTextColor),
                ),
                Text(
                  '(${ResKey.multipleChoices.tr}）',
                  style: ytTextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.normal,
                      color: Colour.lightTextColor),
                ),
              ],
            ),
          ),
          Container(
            height: 52,
            // color: Colors.green,
            child: Row(
              children: [
                Expanded(
                    child: _getPushTypeWidget(0)),
                Expanded(
                    child: _getPushTypeWidget(1,isLeft: false)),
              ],
            ),
          ),
          Container(
            height: 1,
            margin: EdgeInsets.only(left: 16.w, right: 16.w),
            color: Colour.dividerColor,
          ),
          Container(
              height: 50,
              child: Row(
                children: [
                  Container(
                    alignment: Alignment.center,
                    margin: EdgeInsets.only(left: 6.w, right: 2.w),
                    child: Text(
                      '*',
                      style: ytTextStyle(
                          color: Colour.warningTextColor,
                          fontWeight: FontWeight.w500),
                    ),
                  ),
                  Text(
                    ResKey.alarmPushLevel.tr,
                    style: ytTextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.normal,
                        color: Colour.mainTextColor),
                  ),
                  Text(
                    '(${ResKey.multipleChoices.tr}）',
                    style: ytTextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.normal,
                        color: Colour.lightTextColor),
                  ),
                ],
              )),
          Container(
            height: 52,
            // color: Colors.green,
            child: Row(
              children: [
                Expanded(
                    child: _getPushLevelWidget(0),),
                Expanded(
                    child: _getPushLevelWidget(1,isLeft: false),),
              ],
            ),
          ),
          Container(
            height: 52,
            // color: Colors.green,
            child: Row(
              children: [
                Expanded(
                    child: _getPushLevelWidget(2),),
                Expanded(
                    child: _getPushLevelWidget(3,isLeft: false),
                   ),
              ],
            ),
          ),
          // Gaps.vGap20,
          RemarkWidget(
            widget.remarkController,
                (str) {
              Log.d('str==' + str.toString());
              if(widget.callBack != null){
                widget.callBack(str);
              }
              setState(() {

              });
            },
            isCanEdit: widget.isCanEdit,
            isUser: true,
          ),
        ],
      ),
    );
  }

  _getPushTypeWidget(int index,{bool isLeft = true}){
    return GestureDetector(

        onTap: (){
          if(!widget.isCanEdit){
          return;
          }
          if(widget.pushTypeList.contains(index)){
            widget.pushTypeList.remove(index);
          }else{
            widget.pushTypeList.add(index);
          }
          if(widget.pushTypeCallBack != null){
            widget.pushTypeCallBack(widget.pushTypeList);
          }
          setState(() {

          });
        },
        child:  Container(
          height: 34,
          decoration: BoxDecoration(
            color: widget.pushTypeList.contains(index)?Colour.primaryColor.withOpacity(0.1):Colour.backgroundColor,
            borderRadius: BorderRadius.circular(4),
          ),
          alignment: Alignment.center,
          margin:  EdgeInsets.only(left: isLeft?16:0, right: isLeft?12:16),
          child: Text(
            pushTypeStringList[index],
            style: ytTextStyle(
                color: widget.pushTypeList.contains(index)? Colour.primaryColor:Colour.mainTextColor,
                fontWeight: widget.pushTypeList.contains(index)?FontWeight.w500:FontWeight.normal),
          ),
        ));
  }

  _getPushLevelWidget(int index,{bool isLeft = true}){
      return GestureDetector(
          onTap: (){
            if(!widget.isCanEdit){
              return;
            }
        if(widget.pushLevelList.contains(stringList[index])){
          widget.pushLevelList.remove(stringList[index]);
        }else{
          widget.pushLevelList.add(stringList[index]);
        }
        if(widget.pushLeveCallBack != null){
          widget.pushLeveCallBack(widget.pushLevelList);
        }
        setState(() {

        });
      },
    child:  Container(
        height: 34,
        decoration: BoxDecoration(
          color: widget.pushLevelList.contains(stringList[index])?Colour.primaryColor.withOpacity(0.1):Colour.backgroundColor,
          borderRadius: BorderRadius.circular(4),
        ),
        alignment: Alignment.center,
        margin:  EdgeInsets.only(left: isLeft?16:0, right: isLeft?12:16),
        child: Text(
          pushLeveStringList[index],
          style: ytTextStyle(
              color: widget.pushLevelList.contains(stringList[index])? Colour.primaryColor:Colour.mainTextColor,
              fontWeight: widget.pushLevelList.contains(stringList[index])?FontWeight.w500:FontWeight.normal),
        ),
      ));
  }
}

